//
//  NSString+textCheck.m
//  车小喜项目小分支
//
//  Created by Jay_Apple on 15/8/28.
//  Copyright (c) 2015年 Jay_Apple. All rights reserved.
//

#import "NSString+textCheck.h"

@implementation NSString (textCheck)

//邮箱
- (BOOL)checkEmail
{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:self];
}


//手机号码验证
- (BOOL) checkPhoneNum{
    
    NSString *phoneRegex = @"^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$";//@"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:self];
}


//验证码
- (BOOL) checkIndentityCode{
    
    //6位数字或者字母组成
    NSString *IDCode = @"^[0-9a-zA-Z]{6}$";
    NSPredicate *IDCodeTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",IDCode];
    return [IDCodeTest evaluateWithObject:self];

}

//车牌号验证
- (BOOL) checkCarNum
{
    NSString *carRegex = @"^[\u4e00-\u9fa5]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{4}[a-zA-Z_0-9_\u4e00-\u9fa5]$";
    NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex];
    //NSlog(@"carTest is %@",carTest);
    return [carTest evaluateWithObject:self];
}


//车型
- (BOOL) checkCarType
{
    NSString *CarTypeRegex = @"^[\u4E00-\u9FFF]+$";
    NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",CarTypeRegex];
    return [carTest evaluateWithObject:self];
}


//用户名
- (BOOL) checkUsername
{
    NSString *userNameRegex = @"^[A-Za-z0-9]{4,15}$";
    NSPredicate *userNamePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",userNameRegex];
    BOOL B = [userNamePredicate evaluateWithObject:self];
    return B;
}


//密码
- (BOOL) checkPassword
{
    NSString *passWordRegex = @"^[a-zA-Z0-9]{6,15}$";
//    NSString *passWordRegex = @"^.{8,12}$";
    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];
    return [passWordPredicate evaluateWithObject:self];
}


//昵称
- (BOOL) checkNickName
{
    NSString *nicknameRegex = @"^[\u4e00-\u9fa5]{4,8}$";
    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",nicknameRegex];
    return [passWordPredicate evaluateWithObject:self];
}


//身份证号
- (BOOL) checkID
{
    BOOL flag;
    if (self.length <= 0) {
        flag = NO;
        return flag;
    }
    NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$";
    NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];
    return [identityCardPredicate evaluateWithObject:self];
}

//邮政编码
- (BOOL) checPostCode
{
    NSString *postCodeRegex = @"^[0-9]{6}$";
    NSPredicate *postCodePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",postCodeRegex];
    return [postCodePredicate evaluateWithObject:self];
}

/**
 *  价钱
 */
- (BOOL)checkPrice
{
    NSString *postCodeRegex = @"^[1-9]\\d*(\\.\\d*)?$";
    NSPredicate *postCodePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",postCodeRegex];
    return [postCodePredicate evaluateWithObject:self];


}



@end